<!--页面组件-->
<template>
  <div>
    <div class="tempxyz tableHeight">
      <CCard class>
        <CCardHeader>
          <strong class="headerFont">完成任务列表</strong>
        </CCardHeader>
        <CCardBody class="card-body">
          <div class="oneMargin" @keyup.enter="getTaskTableData()">
            <CRow class="twoMargin" style="margin-bottom: 10px">
              <CCol sm="4" class="myCol">
                <label class="labelName">任务名称</label>
                <Input
                  :title="groupName"
                  maxlength="50"
                  style="width: 191px"
                  v-model="groupName"
                  placeholder="请输入任务名称搜索..."
                />
              </CCol>
              <CCol sm="4" class="myCol">
                <label class="labelName youxianji" style>优先级</label>
                <RadioGroup v-model="priority" class="priorityMargin">
                  <Radio label>全部</Radio>
                  <Radio label="0">普通</Radio>
                  <Radio label="1">优先</Radio>
                </RadioGroup>
              </CCol>
            </CRow>
            <CRow class="rowMargin">
              <CCol sm="4" class="myCol">
                <label class="labelName">开始日期</label>
                <DatePicker
                  type="date"
                  placeholder="请选择开始日期"
                  v-model="startDate"
                  class="dateMargin"
                  style="width: 191px"
                  @on-change="onStartTimeChange"
                  :options="startTimeOption"
                  :editable="false"
                ></DatePicker>
              </CCol>
              <CCol sm="4" class="myCol endMargin">
                <label class="labelName">结束日期</label>
                <DatePicker
                  type="date"
                  placeholder="请选择结束日期"
                  v-model="endDate"
                  class="dateMargin"
                  @on-change="onEndTimeChange"
                  :options="endTimeOption"
                  :editable="false"
                ></DatePicker>
              </CCol>
              <CCol sm="3" class="myCol searchPosition">
                <CButton
                  v-c-tooltip="'搜索'"
                  color="info"
                  class="system-btn-style"
                  @click="getTaskTableData()"
                >
                  <CIcon name="cil-magnifying-glass" />&nbsp;搜索
                </CButton>
                <CButton
                  color="info"
                  @click="clearmess"
                  class="myCol clean system-btn-style"
                >
                  <img
                    src="@/assets/icons/chongzhi.png"
                    style="width: 15px; height: 15px"
                    alt
                  />&nbsp; 重置
                </CButton>
              </CCol>
            </CRow>
          </div>

          <div style="height: calc(100% - 157px)">
            <TableList ref="table" :getColumn="getColumns" :getAxios="getAxios">
              <template v-slot:show_details1="item">
                <span v-if="item.data.row.priority == 1"> 优先 </span>
                <span v-if="item.data.row.priority == 0"> 普通 </span>
              </template>
              <template v-slot:show_details2="item">
                <div class="buttonStatus">
                  <CButton
                    v-if="
                      item.data.row.status == 1 && item.data.row.isHuman == 1
                    "
                    class="stastusBtn executing onButton"
                    >执行中</CButton
                  >
                  <CButton
                    v-if="
                      item.data.row.status == 1 && item.data.row.isHuman == 0
                    "
                    class="stastusBtn executing onButton"
                    >执行中</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 2"
                    class="stastusBtn pause onButton"
                    >暂停</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 3"
                    style="color: #f9b115"
                    class="onButton"
                    >删除</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 4"
                    class="stastusBtn success onButton"
                    style="background: #67b9a5;color:white"
                    >成功</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 5"
                    class="stastusBtn success onButton"
                    style="background: #c11113;color:white"
                    >失败</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 6"
                    style="color: #f9b115"
                    class="onButton"
                    >超时</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 7"
                    class="stastusBtn stop onButton"
                    >停止</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 8"
                    class="stastusBtn pending onButton"
                    >待执行</CButton
                  >
                  <CButton
                    v-if="item.data.row.status == 10"
                    class="stastusBtn pending onButton"
                    style="background: #f9b115;color:white;width:70px;margin-left:-5px;"
                    >部分失败</CButton
                  >
                </div>
              </template>
              <template v-slot:show_imageNumber="item">
                <span>
                  {{ item.data.row.imageNumber }} ({{
                    item.data.row.successNumber
                  }}/{{ item.data.row.failNumber }})
                </span>
              </template>
              <template v-slot:show_details="item">
                <Poptip  trigger="hover" word-wrap width="215">
                  <CButton
                      title="查看子任务"
                      variant="outline"
                      class="textBtnStyle onButton system-btn-style"
                      @click="getInfo(item.data.row)"
                  >
                    查看
                  </CButton>
                  <CButton
                      title="删除"
                      variant="outline"
                      @click="del(item.data.row)"
                      class="textBtnStyle onButton system-btn-style"
                      data-permission="Btn_ToExecute_Del"
                  >
                    删除
                  </CButton>
                  <div class="api" slot="content">
                    <CButton
                        v-if="item.data.row.status != 3"
                        title="详情"
                        variant="outline"
                        class="textBtnStyle onButton system-btn-style"
                        @click="getTaskDetails(item.data.row)"
                    >
                      详情
                    </CButton>
                    <CButton
                        v-if="item.data.row.status == 3"
                        title="详情"
                        variant="outline"
                        class="disableTextBtnStyle onButton"
                        @click="() => {}"
                    >
                      详情
                    </CButton>

                    <!--    <CButton
                      :disabled="item.data.row.taskType == 2 ? false : true"
                      v-if="item.data.row.taskType == 2"
                      title="详情"
                      variant="outline"
                      class="textBtnStyle onButton"
                      @click="getTaskDetails(item.data.row)"
                    >
                      详情
                    </CButton>
                    <CButton
                      :disabled="true"
                      v-if="item.data.row.taskType != 2"
                      title="详情"
                      variant="outline"
                      class="disableTextBtnStyle onButton"
                      @click="() => {}"
                    >
                      详情
                    </CButton>-->
                    <CButton
                        title="下载"
                        variant="outline"
                        class="textBtnStyle system-btn-style"
                        @click="downloadTaskResult(item.data.row)"
                    >
                      下载
                    </CButton>
                  </div>
                </Poptip>
              </template>
            </TableList>
          </div>
        </CCardBody>

        <!--CDataTable表格替换-->
        <!--           <CDataTable
            class="tablePosition"
            :items="data"
            :fields="fields"
            hover
            border
          >
            <template #show_details1="{ item }">
              <td>
                <span v-if="item.priority == 1">
                  优先
                  &lt;!&ndash; <span>P1</span> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/highPriority.svg" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/p1.png" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../../public/img/P1.svg" class="levelstyle" alt /> &ndash;&gt;
                </span>
                <span v-if="item.priority == 0">
                  普通
                  &lt;!&ndash; <span>P2</span> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/middlePriority.svg" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../assets/icons/p2.png" class="levelstyle" alt /> &ndash;&gt;
                  &lt;!&ndash; <img src="../../../public/img/P2.svg" class="levelstyle" alt /> &ndash;&gt;
                </span>
              </td>
            </template>
            <template #show_userName="{ item }">
              <td>
                <span v-html="getUserName(item)"></span>
              </td>
            </template>
            <template #show_imageNumber="{ item }">
              <td>
                <span>
                  {{ item.imageNumber }} ({{ item.successNumber }}/{{
                    item.failNumber
                  }})
                </span>
              </td>
            </template>
            <template #show_details2="{ item }">
              <td>
                <button v-if="item.status == 1" class="stastusBtn executing">
                  执行中
                </button>
                <button v-if="item.status == 2" class="stastusBtn pause">
                  暂停
                </button>
                <button v-if="item.status == 3" style="color: #f9b115">
                  删除
                </button>
                <button v-if="item.status == 4" class="stastusBtn success">
                  完成
                </button>
                <button v-if="item.status == 5" class="stastusBtn success">
                  完成
                </button>
                <button v-if="item.status == 6" style="color: #f9b115">
                  超时
                </button>
                <button v-if="item.status == 7" class="stastusBtn stop">
                  停止
                </button>
                <button v-if="item.status == 8" class="stastusBtn pending">
                  待执行
                </button>
              </td>
            </template>
            <template #show_details="{ item }">
              <td>
                <CButton
                  title="查看子任务"
                  variant="outline"
                  class="textBtnStyle"
                  @click="getInfo(item)"
                >
                  查看
                </CButton>
                <CButton
                  :disabled="item.taskType == 2 ? false : true"
                  v-if="item.taskType == 2"
                  title="详情"
                  variant="outline"
                  class="textBtnStyle"
                  @click="getTaskDetails(item)"
                >
                  详情
                </CButton>
                <CButton
                  :disabled="true"
                  v-if="item.taskType != 2"
                  title="详情"
                  variant="outline"
                  class="disableTextBtnStyle"
                  @click="() => {}"
                >
                  详情
                </CButton>
                &lt;!&ndash; <CButton
                  title="下载"
                  variant="outline"
                  class="textBtnStyle"
                  @click="downloadTaskResult(item)"
                >
                下载
                </CButton> &ndash;&gt;
                <CButton
                  title="删除"
                  variant="outline"
                  @click="del(item)"
                  class="textBtnStyle"
                  data-permission="Btn_End_Del"
                >
                  删除
                </CButton>
                &lt;!&ndash; <CButton
                  :disabled="item.status == 1 ? false : true"
                  v-if="item.status == 1"
                  v-c-tooltip="'暂停'"
                  title="暂停"
                  variant="outline"
                  class="btnStyle"
                  @click="pause(item)"
                  data-permission="Btn_End_Pause"
                >
                  <CIcon class="colortempstyle" name="cil-media-pause" />
                </CButton>
                <CButton
                  :disabled="item.status == 1 ? false : true"
                  v-if="item.status != 1"
                  v-c-tooltip="'暂停'"
                  title="暂停"
                  variant="outline"
                  class="btnStyle"
                  @click="pause(item)"
                  data-permission="Btn_End_Pause"
                >
                  <CIcon class="notcolortempstyle" name="cil-media-pause" />
                </CButton>
                <CButton
                  :disabled="item.status == 2 ? false : true"
                  v-c-tooltip="'恢复'"
                  title="恢复"
                  v-if="item.status == 2"
                  variant="outline"
                  class="btnStyle"
                  @click="restore(item)"
                  data-permission="Btn_End_Restore"
                >
                  <CIcon class="colortempstyle" name="cil-media-stop" />
                </CButton>
                <CButton
                  :disabled="item.status == 2 ? false : true"
                  v-c-tooltip="'恢复'"
                  title="恢复"
                  v-if="item.status != 2"
                  variant="outline"
                  class="btnStyle"
                  @click="restore(item)"
                  data-permission="Btn_End_Restore"
                >
                  <CIcon class="notcolortempstyle" name="cil-media-stop" />
                </CButton> &ndash;&gt;
              </td>
            </template>
          </CDataTable>
        </CCardBody>
        <CCardFooter class="page-link">
          <CRow>
            <CCol class="footerPage" style>
              <span class="pageContent">
                每页
                <CSelect
                  @change="getVendorId($event)"
                  :options="[10, 15, 20, 25]"
                  v-model="pageSize"
                  class="selectStyle"
                />
                条记录。第{{ this.currentPage }}页(总共{{ this.total }}页，{{
                  this.allNum
                }}条记录)
              </span>
              <CPagination
                :activePage.sync="currentPage"
                :pages="total"
                align="end"
                v-if="total != 0"
              />
            </CCol>
          </CRow>
        </CCardFooter>-->
      </CCard>
    </div>
    <!-- <CModal
      :show.sync="delShow"
      :closeOnBackdrop="false"
      title="删除主任务"
      centered
    >
      <template #header class="taskExecuteHeader">
        <img src="@/assets/icons/shanchu.svg" alt />
        <p class="delKuangShow">删除主任务</p>
      </template>
      <div class="modalBody">
        <p>删除主任务时与主任务相关的信息都会丢失</p>
        <p>请确认是否删除?</p>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="delCancel" color="info" class="cancel-btn">取消</CButton>
        <CButton @click="delOk" color="info">确定</CButton>
      </template>
    </CModal> -->
    <!-- <CModal
      :show.sync="pauseShow"
      :closeOnBackdrop="false"
      title="暂停任务"
      centered
    >
      <p>确认要暂停任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="pauseCancel" color="info">取消</CButton>
        <CButton @click="pauseOk" color="info">确定</CButton>
      </template>
    </CModal> -->
    <!-- <CModal
      :show.sync="restoreShow"
      :closeOnBackdrop="false"
      title="恢复任务"
      centered
    >
      <p>确认要恢复任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restoreCancel" color="info">取消</CButton>
        <CButton @click="restoreOk" color="info">确定</CButton>
      </template>
    </CModal>
    <CModal
      :show.sync="restartShow"
      :closeOnBackdrop="false"
      title="重启任务"
      centered
    >
      <p>确认要重启任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="reStartCancel" color="info">取消</CButton>
        <CButton @click="reStartOk" color="info">确定</CButton>
      </template>
    </CModal> -->
    <Modal
      v-model="delShow"
      draggable
      scrollable
      title="删除主任务"
      :styles="modalStyle"
    >
      <p slot="header" class="modalHeader">
        <img src="@/assets/icons/shanchu.svg" alt />
        <span style="margin-left: 5px">删除主任务</span>
      </p>
      <div class="modalBody">
        <p>删除主任务时与主任务相关的信息都会丢失</p>
        <p>请确认是否删除?</p>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="delShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="delOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="pauseShow"
      draggable
      scrollable
      title="暂停任务"
      :styles="modalStyle"
    >
      <p>确认要暂停任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="pauseCancel" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="pauseOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restoreShow"
      draggable
      scrollable
      title="恢复任务"
      :styles="modalStyle"
    >
      <p>确认要恢复任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restoreShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="restoreOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restartShow"
      draggable
      scrollable
      title="重启任务"
      :styles="modalStyle"
    >
      <p>确认要重启任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="reStartShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="reStartOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <!--下载-->
    <!-- footer-hide -->
    <Modal
      v-model="showdownLoad"
      draggable
      scrollable
      title="下载列表"
      :styles="modalStyle"
      class="downLoadModal"
    >
      <!-- 复选 : show-checkbox -->
      <Tree
        @on-select-change="selectTree"
        :data="treeData"
        ref="tree"
        class="demo-tree-render"
        style="overflow: auto"
      ></Tree>
      <template #footer class="footerBtns">
        <CButton @click="showdownLoad = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="downLoadProduct" color="info" class="system-btn-style"
          >下载</CButton
        >
      </template>
    </Modal>
    <!-- 质检报告 -->
    <div>
      <QualityReport
        ref="refQcReportModal"
        v-show="qcReportModal"
        :modalShow="qcReportModal"
        @closed="qcReportModalClosed"
      ></QualityReport>
    </div>
  </div>
</template>

<script>
import TableList from "@/template/table/TableList";
import QualityReport from "../qualityCheck/qualityReport";
const fields = [
  {
    label: "序号",
    key: "number",
    _style: "width:60px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "任务名称",
    key: "groupTaskName",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "任务来源",
    key: "taskSourceName",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "用户名",
    key: "taskOwner",
    _style: "width:auto;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "开始时间",
    key: "createTime",
    _style: "width:170px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "结束时间",
    key: "endTime",
    _style: "width:170px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "优先级",
    key: "show_details1",
    _style: "width:75px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "景数(成功/失败)",
    key: "show_imageNumber",
    _style: "width:120px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "状态",
    key: "show_details2",
    _style: "width:90px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
  {
    label: "操作",
    key: "show_details",
    _style: "width:240px;text-align: center;background:rgba(241,244,249,1);",
    align: "center",
  },
];

export default {
  name: "taskEnd",
  components: {
    QualityReport,
    TableList,
  },
  data() {
    return {
      userName: window.sessionStorage.getItem("user"),
      modalStyle: { top: "200px" },
      restartShow: false,
      qcReportModal: false,
      fields,
      pauseShow: false,
      restoreShow: false,
      delShow: false,
      clickId: "",
      loading: true,
      currentPage: 1,
      pages: 0,
      total: 0,
      allNum: 0,
      pageSize: 15,
      priority: "",
      taskStatus: "4,5,6,10",
      searchName: "",
      groupName: "",
      data: [],
      startDate: "",
      endDate: "",
      startTimeOption: {},
      endTimeOption: {},
      children: [],
      condtionList: {
        pageNum: "",
        pageSize: "",
        status: "",
        priorityLevel: "",
        startTime: "",
        endTime: "",
      },

      getColumns: [
        {
          title: "任务名称",
          key: "groupTaskName",
        },
        {
          title: "任务来源",
          key: "taskSourceName",
          width: 100,
          className: "centerText",
        },
        {
          title: "用户名",
          key: "taskOwner",
          // slot: "taskOwner",
          width: 100,
          className: "centerText",
        },
        {
          title: "开始时间",
          key: "createTime",
          width: 170,
          className: "centerText",
        },
        {
          title: "结束时间",
          key: "endTime",
          width: 170,
          className: "centerText",
        },
        {
          title: "优先级",
          key: "show_details1",
          slot: "show_details1",
          width: 90,
          className: "centerText",
        },
        {
          title: "景数(成功/失败)",
          key: "show_imageNumber",
          slot: "show_imageNumber",
          width: 140,
          className: "centerText",
        },
        {
          title: "状态",
          key: "show_details2",
          slot: "show_details2",
          width: 90,
          className: "centerText",
        },
        {
          title: "操作",
          key: "show_details",
          slot: "show_details",
          className: "centerText",
          width: 160,
        },
      ],
      getAxios: {
        url: this.$api.taskManageApi.query, //请求路径
        method: "get", //请求方式
        dataList: {
          status: "4,5,6,10",
          userName: window.sessionStorage.getItem("user"),
        }, //请求参数
      },
      showdownLoad: false,
      treeData: [],
      productpath: "",
      setIntervalTime: "",
    };
  },
  computed: {
    getColumn() {
      return [
        {
          key: "groupName",
          title: "任务名称",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.groupName,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.groupName
              ),
            ]);
          },
        },
        {
          key: "createTime",
          title: "创建时间",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.createTime,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.createTime
              ),
            ]);
          },
        },
        {
          key: "ms",
          title: "用时",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "div",
                {
                  style: {
                    display: "inline-block",
                    width: "100%",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    whiteSpace: "nowrap",
                  },
                  domProps: {
                    title: params.row.ms,
                  },
                  props: {
                    color: "info",
                    variant: "outline",
                  },
                },
                params.row.ms
              ),
            ]);
          },
        },
        { key: "progress", title: "进度", align: "center" },
        { key: "successRate", title: "成功率", align: "center" },
        {
          key: "priorityLevel",
          title: "优先级",
          align: "center",
          render: (h, params) => {
            if (params.row.priorityLevel == 1) {
              return h("span", "优先");
            } else if (params.row.priorityLevel == 0) {
              return h("span", "普通");
            }
          },
        },
        {
          key: "status",
          title: "状态",
          align: "center",
          render: (h, params) => {
            if (params.row.status == 1) {
              return h("span", "执行中");
            } else if (params.row.status == 2) {
              return h("span", "暂停");
            } else if (params.row.status == 3) {
              return h("span", "删除");
            } else if (params.row.status == 4) {
              return h("span", "成功");
            } else if (params.row.status == 5) {
              return h("span", "失败");
            } else if (params.row.status == 6) {
              return h("span", "超时");
            } else if (params.row.status == 7) {
              return h("span", "停止");
            } else if (params.row.status == 8) {
              return h("span", "待执行");
            }
          },
        },
        {
          title: "操作",
          width: "180px",
          slot: "action",
          align: "center",
        },
      ];
    },
    getColumnlist() {
      return [
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          key: "productName",
          title: "质检报告文件(文件夹)",
          render: (h, params) => {
            return h("div", [
              h(
                "span",
                {
                  style: {},
                  //就是这里加的属性
                  domProps: {
                    title: params.row.productName,
                  },
                },
                params.row.productName
              ),
            ]);
          },
        },
        {
          title: "操作",
          width: "150px",
          slot: "action",
          align: "center",
        },
      ];
    },
  },
  mounted() {
    // 查询子任务页面返回调用
    // if (this.$route.query.from === "taskChildren") {
    //   // this.currentPage = parseInt(this.$route.query.pageNum);
    //   // this.search();
    // }
    /* this.getTaskTableData();*/
    // this.getContent()
    this.userName = window.sessionStorage.getItem("user");
    this.onStartTimeChange(this.startTime);
    this.onEndTimeChange(this.endTime);
  },
  methods: {
    // 下载产品 客户端下载
    // downloadTaskResult(item) {
    //   if (item.taskType === 2) {
    //     let path = this.$api.taskManageApi.getTaskProductFile + item.id;
    //     let param = { userName: this.userName };
    //     this.http.get(path, param).then((res) => {
    //       if (res.data.code == 0) {
    //         let data = res.data.data;
    //         let filePath = data.isFile ? data.file : data.file + "/";
    //         let url =
    //           "DownloadFile://" +
    //           sessionStorage.getItem("PIECloud-Token") +
    //           "/" +
    //           this.userName +
    //           "/" +
    //           filePath +
    //           "/";
    //         if (data.isUserFile) {
    //           let r = window.confirm("暂无影像产品数据,是否跳转根目录？");
    //           if (r) {
    //             this.$$openDownLoadFile(url);
    //           }
    //         } else {
    //           this.$$openDownLoadFile(url);
    //         }
    //       } else {
    //         this.$Message.error(res.data.message);
    //       }
    //     });
    //   } else {
    //     //质量检查详情
    //     this.$refs.refQcReportModal.openOrClose();
    //     this.$refs.refQcReportModal.getTaskDetails(item, "parent");
    //   }
    // },
    // 下载产品
    downloadTaskResult(item) {
      let _this = this;
      if (/*item.taskType == 2*/ true) {
        let path = this.$api.taskManageApi.taskDetailResult + item.id;
        let params = {
         /* productType: 2,*/
          productType: -1,
        };
        this.http.get(path, params).then((res) => {
          if (res.data.code == 0) {
            if (res.data.data.length < 1) {
              this.$Message.warning("暂无影像产品数据");
            } else {
              _this.showdownLoad = true;
              _this.treeData = _this.getNewTreeData(res.data.data);
            }
          } else {
            this.$Message.error(res.data.message);
          }
        });
      } else {
        this.$refs.refQcReportModal.openOrClose();
        this.$refs.refQcReportModal.getTaskDetails(item, "parent");
      }
    },

    downLoadProduct() {
      if (this.productpath == null || this.productpath == "") {
        this.$Message.warning("请选择下载的产品文件");
        return;
      }
      /*
        let data = {
          path: this.$api.taskManageApi.isExit,
          params: {
            username: this.$store.state.user.userName,
            path: this.productpath,
            // path:  "/pie/data/247/sthx_user_data/pieadmin/lilintest/123/GF3_KAS_QPSI_010970_E81.2_N40.5_20180910_L1A_VH_L10003442728.tif", //测试地址
          },
        };

        let fun = function () {
          let url =
            "DownloadFile://" +
            sessionStorage.getItem("PIECloud-Token") +
            "/" +
            data.params.username +
            "/" +
            data.params.path +
            "/";
          window.location.href = url;
        };
           this.$$downLoadFile(data, fun);
    */
      let newarr = [];
      newarr.push(this.productpath);
      let path = this.GlobalUrlPath.qualityCheck.downloadReport + newarr;
      window.open(path);
    },
    //提取文件夹里面所有的文件
    getNewTreeData(data) {
      let _this = this;
      let result = [];
      for (let i = 0; i < data.length; i++) {
        let tempItem = data[i];
        let item = {};
        item.expand = tempItem.expand;
        item.path = tempItem.path;
        item.title = tempItem.title;
        item.type = tempItem.type;
        item.children = [];
        result.push(item);

        if (tempItem.type == "folder" && tempItem.children) {
          let list = [];
          _this.recursiveTreeFile(tempItem.children, list);
          item.children = list;
        }
      }
      return result;
    },
    recursiveTreeFile(data, list) {
      let _this = this;
      for (let i = 0; i < data.length; i++) {
        let tempItem = data[i];
        if (tempItem.type == "file") {
          list.push(tempItem);
        }
        if (tempItem.type == "folder" && tempItem.children) {
          _this.recursiveTreeFile(tempItem.children, list);
        }
      }
      return list;
    },
    qcReportModalClosed() {
      this.qcReportModal = false;
    },
    selectTree() {
      let item = this.$refs.tree.getSelectedNodes()[0];
      if (!item) return;
      this.productpath = this.$refs.tree.getSelectedNodes()[0].path;
      if (item.type === "folder") {
        item.expand = !item.expand;
        item.selected = !item.selected;
        return;
      }
    },

    getTaskDetails(item) {
      if (item.taskType == 2) {
        this.$router.push({
          path: "/processing",
          query: {
            from: "taskLook",
            id: item.id,
            status: item.status,
          },
        });
      } else {
        this.qcReportModal = true;
        this.$refs.refQcReportModal.getTaskDetails(item, "parent");
      }
    },
    getVendorId(event) {
      let tempdata = event.target.value; //获取option对应的value值
      this.pageSize = parseInt(tempdata);
    },

    clearmess() {
      this.currentPage = 1;
      this.groupName = "";
      this.startDate = "";
      this.endDate = "";
      this.priority = "";
      // this.taskStatus = "";
      this.getTaskTableData();
    },
    // 输入框判断 start
    onStartTimeChange(startTime, type) {
      this.endTimeOption = {
        disabledDate(endTime) {
          // return endTime < new Date(startTime) || endTime > Date.now();
          return (
            endTime < new Date(startTime) - 8 * 60 * 60 * 1000 ||
            endTime > Date.now()
          );
        },
      };
    },
    onEndTimeChange(endTime, type) {
      this.startTimeOption = {
        disabledDate(startTime) {
          // return startTime > new Date(endTime) || startTime > Date.now();
          return startTime >= new Date(endTime) || startTime >= Date.now();
        },
      };
    },
    // end
    getInfo(val) {
      String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
      };
      let userLink =
        `/taskManage/allTask/${val.id}/${val.groupTaskName.replaceAll(
          "/",
          "*"
        )}` + "?"
        //  +
        // val.number;
      this.$router.push({
        path: userLink,
        query: {
          // pageNum: this.currentPage,
          from: "taskEnd",
          taskType: val.taskType,
        },
      });
    },

    del(val) {
      this.delShow = true;
      this.clickId = val.id;
    },
    delOk() {
      let self = this;
      this.delShow = false;
      let path = this.$api.taskManageApi.delete + this.clickId;
      this.http.delete(path).then((res) => {
        if (res.data.code == 0) {
          this.$Message.success("删除成功");
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("删除失败");
        }
      });
    },
    pause(val) {
      this.pauseShow = true;
      this.clickId = val.id;
    },
    pauseCancel() {
      this.pauseShow = false;
    },
    pauseOk() {
      let self = this;
      self.pauseShow = false;
      let statusName = "PAUSED";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    restore(val) {
      this.restoreShow = true;
      this.clickId = val.id;
    },

    restoreOk() {
      let self = this;
      this.restoreShow = false;
      let statusName = "RESUME";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    reStart(val) {
      this.reStartShow = true;
      this.clickId = val.id;
    },

    reStartOk() {
      let self = this;
      this.reStartShow = false;
      let statusName = "RESTART";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        self.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    getTaskTableData(data = false) {
      let self = this;
      self.data = [];

      if (self.endDate == "Invalid date") {
        self.endDate = "";
      }
      if (self.startDate == "Invalid date") {
        self.startDate = "";
      }
      let path = this.$api.taskManageApi.query;
      let param = {
        currentPageNum: data,
        status: self.taskStatus,
        priority: self.priority,
        startTime: self.startDate,
        endTime: self.endDate,
        name: self.groupName,
        userName: this.userName,
      };
      this.$refs.table.getRefreshTable(param);
      /*      this.http.get(path, param).then((res) => {
        console.log("aaaaaaaaaaaaaa", res);
        self.loading = false;
        if (res.data.code == 0) {
          self.allNum = res.data.data.total;
          // self.data = res.data.data.dataList;

          let resData = res.data.data.dataList;
          let dataa = [];
          for (let i = 0; i < resData.length; i++) {
            // 截取掉时间
            let index = resData[i].groupTaskName.lastIndexOf(" ");
            let groupTaskNameNew2 = resData[i].groupTaskName.substring(
              0,
              index
            );
            dataa.push({
              createTime: resData[i].createTime,
              endTime: resData[i].endTime,
              failNumber: resData[i].failNumber,
              groupTaskName: resData[i].groupTaskName,
              taskSourceName: resData[i].taskSourceName,
              // groupTaskName:groupTaskNameNew2,
              id: resData[i].id,
              imageNumber: resData[i].imageNumber,
              number: resData[i].number,
              priority: resData[i].priority,
              runTime: resData[i].runTime,
              starTime: resData[i].startTime,
              status: resData[i].status,
              successNumber: resData[i].successNumber,
              taskType: resData[i].taskType,
              userId: resData[i].userId,
              workFlowId: resData[i].workFlowId,
            });
          }
          self.data = dataa;

          self.total = Math.ceil(res.data.data.total / self.pageSize);
          for (let i = 0; i < self.data.length; i++) {
            self.data[i].number =
              (self.currentPage - 1) * this.pageSize + i + 1;
            if (self.data[i].endTime == null) {
              self.data[i].endTime = "";
            }
          }

          // self.startDate = "";
          // self.endDate = "";
          //  self.groupName = ""
        } else {
          this.$Message.error("查询失败");
        }
      });*/
    },
  },
  activated() {
    let that = this;
    that.getTaskTableData(true);
    that.$bus.$emit("getTaskCatalog");
    this.setIntervalTime = setInterval(function () {
      that.$bus.$emit("getTaskCatalog");
      that.getTaskTableData(true);
    }, 5000);
  },
  deactivated() {
    clearInterval(this.setIntervalTime);
  },
  watch: {
    data(newVal, oldVal) {
      this.$nextTick(function () {
        this.GlobalPermissionRender.render();
      });
    },
    groupName(newVal, oldVal) {
      if (newVal.length >= 50) {
        this.$Message.warning("任务名称长度不得超过50个字符");
      }
    },
    // pageSize(newVal, oldVal) {
    //   this.pageSize = newVal;
    //   this.getTaskTableData();
    // },
    // currentPage(newVal, oldVal) {
    //   this.currentPage = newVal;
    //   this.getTaskTableData();
    // },
    startDate(newVal, oldVal) {
      this.startDate = this.$moment(newVal).format("YYYY-MM-DD HH:mm:ss");
    },
    endDate(newVal, oldVal) {
      this.endDate = this.$moment(newVal).format("YYYY-MM-DD HH:mm:ss");
    },
  },
};
</script>

<!--css样式-->
<style scoped>
.myCol {
  margin-left: 10px;
}
.search {
  display: flex;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.76563rem;
  line-height: 1.5;
  border-radius: 0.2rem;
  width: 50px;
}
.table-responsive {
  height: 50% !important;
}
.labelName {
  margin-left: -15px;
  margin-right: 10px;
}
.headerFont {
  font-size: 18px;
}

.groupNameWidth {
  width: 197px;
}
.ivu-radio-wrapper {
  margin-left: 0px;
}

.dateMargin {
  margin-top: -5px;
}
.endMargin {
  margin-left: 19px;
}
.btnStyle {
  margin-left: 3px;
}
.youxianji {
  margin-left: -5px;
  margin-right: 25px;
}
.ivu-radio-group {
  margin-top: 7px;
}
.btn-info {
  width: 90px;
}

.clean {
  margin-left: 10px;
}
.page-link {
  cursor: pointer;
}
.pageContent {
  margin-right: 26px;
  font-size: 14px;
}
.selectStyle {
  display: inline-block;
  width: 100px;
  margin-right: 5px;
}
.footerPage {
  display: flex;
  justify-content: flex-end;
  cursor: pointer;
  color: black;
}

/* xg */
.btnStyle {
  padding: 0;
  margin: 0 3px;
}
/* 用以调整表格位置 */
.tablePosition {
  overflow-y: auto;
  height: calc(100% - 153px);
}

/*
修改表格样式
*/
/deep/ .row {
  margin-right: 0;
}

/deep/ .footerPage {
  padding-right: 0;
}

/deep/.ivu-table td.centerText {
  text-align: center;
  text-align: -moz-center;
  text-align: -webkit-center;
}

.card-body {
  overflow-y: auto;
  height: calc(100% - 52px) !important;
}

.twoMargin {
}
.rowMargin {
}
.searchPosition {
  margin-top: -10px;
}
.oneMargin {
  margin: 10px 0 10px 10px;
}
</style>
<style scoped>
.onButton:hover {
  color: white;
}
.tempxyz .card-body {
  position: static;
  padding: 0 20px;
}

.buttonStatus /deep/ .btn:focus {
  -webkit-box-shadow: 0 0 0 0;
  box-shadow: 0 0 0 0;
}
</style>
